﻿using System;
using System.Text;
using System.Collections.Generic;
using System.Linq;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using FeedNet;
using System.IO;

namespace TestFeedNet
{
    /// <summary>
    /// Summary description for TestFeedUpdates
    /// </summary>
    [TestClass]
    public class TestFeedUpdates
    {

        Feed f;

        [TestMethod]
        public void testUpdateHackety()
        {
            Feeder testFeeder = new Feeder();

            string path = Path.Combine(Environment.CurrentDirectory, @"..\..\..\TestFeedNet\ATOM_testcase_hackety.org.txt");
            FileStream fs = File.Open(path, FileMode.Open, FileAccess.Read, FileShare.ReadWrite);

            f = testFeeder.getFeedFromStream(fs);
            fs.Close();


            f.feed_url = @"..\..\..\TestFeedNet\ATOM_testcase_hackety.org.update.txt";
            f = testFeeder.updateFeed(f);

            Assert.AreEqual(1, f.new_entries.Count);
            Assert.AreEqual("NEWONE", f.entries.First().title);
            Assert.AreEqual("NEWONE", f.new_entries.First().title);
        }

        [TestMethod]
        public void testUpdateRSS()
        {
            Feeder testFeeder = new Feeder();

            string path = Path.Combine(Environment.CurrentDirectory, @"..\..\..\TestFeedNet\RSS_testcase.txt");
            FileStream fs = File.Open(path, FileMode.Open, FileAccess.Read, FileShare.ReadWrite);

            f = testFeeder.getFeedFromStream(fs);
            fs.Close();

            f.feed_url = @"..\..\..\TestFeedNet\RSS_testcase_update.txt";
            f = testFeeder.updateFeed(f);

            Assert.AreEqual(1, f.new_entries.Count);
            Assert.AreEqual("NEWONE", f.entries.First().title);
            Assert.AreEqual("NEWONE", f.new_entries.First().title);
        }
    }
}
